package com.deyang.mycommon.mvp.model;

import android.os.Handler;

import com.deyang.mycommon.entity.BaseAdapterTestItem;
import com.deyang.mycommon.mvp.mvpcallback.ValueCallBack;
import com.deyang.mycommon.util.Logger;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class BaseAdapterModelImpl implements IBaseAdapterModel {

    private static final String TAG = "BaseAdapterModelImpl";

    private List<BaseAdapterTestItem> listData;

    public BaseAdapterModelImpl() {
        listData = new ArrayList<>();
    }

    @Override
    public void loadData(final ValueCallBack<List<BaseAdapterTestItem>> callBack) {
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                List<BaseAdapterTestItem> testItemList = new ArrayList<>();
                testItemList.add(new BaseAdapterTestItem(0xffff8308, "信息"));
                testItemList.add(new BaseAdapterTestItem(0xfffb0402, "错误"));
                testItemList.add(new BaseAdapterTestItem(0xffff8308, "正确"));
                testItemList.add(new BaseAdapterTestItem(0xff3F51B5, "警告"));

                Random rd = new Random();
                int n = rd.nextInt(10);
                Logger.e(TAG, "ssss  N : " + n);
                if (n > 8) {
                    callBack.onFail("拒绝请求");
                } else {
                    callBack.onSuccess(testItemList);
                }
            }
        }, 1000);
    }

    @Override
    public List<BaseAdapterTestItem> getBaseAdapterItemList() {
        return listData;
    }
}
